from app import app, db
from models.user import User
from werkzeug.security import generate_password_hash

def create_test_user():
    """创建测试用户"""
    with app.app_context():
        # 检查用户是否已存在
        existing_user = User.query.filter_by(username='admin').first()
        if existing_user:
            print("测试用户已存在")
            return
            
        # 创建测试用户
        user = User(
            username='admin',
            email='admin@example.com',
            password_hash=generate_password_hash('admin123')
        )
        
        db.session.add(user)
        db.session.commit()
        print("测试用户创建成功")
        print("用户名: admin")
        print("密码: admin123")

if __name__ == "__main__":
    create_test_user()